﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ETM.Business.Models;
using ETM.Data.DataTransferObjects;
using ETM.Data.Interfaces;
using ETM.Data.Repositories;

namespace ETM.Business.Handlers
{
    public class GetTask
    {
        private readonly ITaskRepository taskRepo;

        public GetTask()
        {
            taskRepo = TaskMockupRepository.Instance;
        }

        public List<Task> ByStatus(string status)
        {
            var dto = new GetTaskDto { Limited = -1, Status = status };
            var result = taskRepo.GetTaskEntities(dto);

            if (result != null)
            {
                var tasks = from entity in result
                            select
                                new Task
                                    {
                                        TaskId = entity.TaskId,
                                        TaskStatus = entity.TaskStatus, 
                                        TaskName = entity.TaskName,
                                        IsImportant = entity.IsImportant,
                                        IsUrgent = entity.IsUrgent,
                                        CreatedDate = entity.CreatedDate
                                    };
                return tasks.ToList();
            }

            return new List<Task>();

        }

        public List<Task> All()
        {
            var dto = new GetTaskDto { Limited = -1 };
            var result = taskRepo.GetTaskEntities(dto);

            if (result != null)
            {
                var tasks = from entity in result
                            select
                                new Task
                                {
                                    TaskId = entity.TaskId,
                                    TaskStatus = entity.TaskStatus,
                                    TaskName = entity.TaskName,
                                    IsImportant = entity.IsImportant,
                                    IsUrgent = entity.IsUrgent,
                                    CreatedDate = entity.CreatedDate
                                };
                return tasks.ToList();
            }

            return new List<Task>();

        }
    }
}
